/**
 * MyApplyAction.java
 */
package com.prs.crm.action.official;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.prs.crm.domain.approval.Application;
import com.prs.crm.domain.ca.work.PurchaseApply;
import com.prs.crm.domain.official.MyApply;
import com.prs.crm.service.approval.ApplicationService;
import com.prs.crm.service.official.MyApplyService;

/**
 * @author ZhuDongMei
 * @E-mail:1223984339@qq.com
 * @qq:1223984339
 * @version 创建时间：2011-3-16 上午11:12:28 简单说明
 */

public class MyApplyAction extends BaseAction {
	private static final long serialVersionUID = 1L;
    private MyApply myApply;
    private MyApplyService myApplyService;
    private PaginationSupport pagination;
    private PurchaseApply purchaseApply;
    private Integer[] myApplyIds;
    private Application application;
    private ApplicationService applicationService;
	public ApplicationService getApplicationService() {
		return applicationService;
	}
	public void setApplicationService(ApplicationService applicationService) {
		this.applicationService = applicationService;
	}
	public Application getApplication() {
		return application;
	}
	public void setApplication(Application application) {
		this.application = application;
	}
	public Integer[] getMyApplyIds() {
		return myApplyIds;
	}
	public void setMyApplyIds(Integer[] myApplyIds) {
		this.myApplyIds = myApplyIds;
	}
	public PurchaseApply getPurchaseApply() {
		return purchaseApply;
	}
	public void setPurchaseApply(PurchaseApply purchaseApply) {
		this.purchaseApply = purchaseApply;
	}
	public MyApply getMyApply() {
		return myApply;
	}
	public void setMyApply(MyApply myApply) {
		this.myApply = myApply;
	}
	public MyApplyService getMyApplyService() {
		return myApplyService;
	}
	public void setMyApplyService(MyApplyService myApplyService) {
		this.myApplyService = myApplyService;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	@Action("listMyApply")
	public String listMyApply(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(MyApply.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMyApplyService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("viewMyApply")
	public String viewMyApply(){
		this.purchaseApply = myApply.getPurchaseApply();
		return SUCCESS;
	}
	@Action(value = "view", results = {
			@Result(name = "success", type = "redirect", location = "viewMyApply?myApply=${myApply.getId()}"),
			@Result(name = "error", type = "chain", location = "listMyApply") })
	public String view(){
		if(myApplyIds!=null){
			this.myApply = this.getMyApplyService().get(myApplyIds[0]);
		}
		return SUCCESS;
	}
	@Action("listWaiting")
	public String listWaiting(){
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(MyApply.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getMyApplyService().listByPage(criteria, pagination));
		return SUCCESS;
	}
}
